package com.misboot.document.client.fallbackFactory;

import cn.ewsd.common.controller.BaseController;
import com.misboot.document.client.MessageClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * 消息中心模块降级处理
 *
 * @Author 湖南佐佑时代科技有限公司
 * @Email service@zuoyo.com
 * @Date 2020-01-19 14:19:26
 */
@Component
public class MessageClientFallbackFactory extends BaseController implements FallbackFactory<MessageClient> {

    private static final Logger log = LoggerFactory.getLogger(MessageClientFallbackFactory.class);


    @Override
    public MessageClient create(Throwable throwable) {
        log.error("消息中心模块调用失败:{}", throwable.getMessage());

        return new MessageClient() {

            @Override
            public Object sendSimpleMail(Map<String, Object> map) {
                return failure("服务器开小差了，请稍后再试！！！");
            }

            @Override
            public Object sendSms(String phoneNumbers, String signName, String templateCode, String templateParam, String SenderId) {
                return failure("服务器开小差了，请稍后再试！！！");
            }

            @Override
            public Object save(Map<String, Object> map) {
                return failure("服务器开小差了，请稍后再试！！！");
            }
        };
    }
}
